import allure
from selenium.webdriver.common.by import By
from base.base_action import BaseAction


class PageLogin(BaseAction):
    def __init__(self, driver):
        super().__init__(driver)
        # 元素：用户名输入框
        self.__username_input = By.XPATH, "//*[@type='text']"
        # 元素：显示密码按钮
        self.__show_password = By.XPATH, "//*[@type='password']"
        # 元素：登录按钮
        self.__login_btn = By.XPATH, "//*[@class='el-button el-button--primary is-round login_btn_all']"

        # 元素：警告框
        self.__alert = By.CLASS_NAME, "ivu-message"
        # # 元素：手机号登录
        # self.loginByIphone=By.XPATH,'//*[text()="手机号/身份证号登录"]'
        # # 元素:学号登录
        # self.loginByStudyNumber=By.XPATH,'//*[text()="学号登录"]'

        # 元素：网校运营中心
        self.__network_school = By.XPATH, "//*[contains(text(), '网校运营中心')]"


    @allure.step(title="操作步骤:输入用户名")
    def input_username(self, username):
        return self.inputs(self.__username_input, username)

    @allure.step(title="操作步骤:输入密码")
    def input_passwd(self, passwd):
        return self.input(self.__show_password, passwd)

    @allure.step(title="操作步骤:点击登录")
    def click_login_btn(self):
        return self.click(self.__login_btn)

    @allure.step(title="操作步骤:点击显示密码")
    def click_show_password(self):
        return self.click(self.__show_password)

    @allure.step(title="操作步骤:获取警告框的内容")
    def get_alert_info(self):
        return self.getTextContent(self.__alert)

    @allure.step(title="操作步骤:获取网校运营中心文本")
    def get_network_school_info(self):
        return self.getTextContent(self.__network_school)


    @allure.step(title="操作步骤:判断操作按钮是否存在，存在返回False")
    def isNotExistLoginBtn(self):
        return self.eleIsNotExist(self.__login_btn)
